package com.ty.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ty.entity.Order;
import com.ty.mapper.OrderMapper;
import com.ty.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param orderId 主键
     */
    @Override
    public Order queryById(Integer orderId){
       Order order= orderMapper.queryById(orderId);
       return order;
    }


    /**
     * 新增数据
     *
     * @param order 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(Order order){
         orderMapper.insert(order);
        return 1;
    }

    @Override
    public int insertBatch(List<Order> entities) {
        orderMapper.insertBatch(entities);
        return 1;
    }

    /**
     * 更新数据
     *
     * @param order 实例对象
     * @return 实例对象
     */
    @Override
    public int update(Order order){
         orderMapper.update(order);
        return 1;
    }

    /**
     * 通过主键删除数据
     *
     * @param orderId 主键
     * @return 是否成功
     */
    @Override
    public int deleteById(Integer orderId){
         orderMapper.deleteById(orderId);
        return 1;
    }

    @Override
    public int updateStatusToPaySuccess(Integer orderId){
        orderMapper.updateStatusToPaySuccess(orderId);
        return 1;
    }

    @Override
    public int cancelOrders(Integer orderId){
          orderMapper.cancelOrders(orderId);
        return 1;
    }

    @Override
    public List<Order> getByOrderIdAndUserId(Integer orderId,Integer userId){
       List<Order> list = orderMapper.getByOrderIdAndUserId(orderId,userId);
       return list;
    }

    public int receiedOrder(Integer orderId){
        orderMapper.receiedOrder(orderId);
        return 1;
    }

}
